<template>
  <!-- 今日咨询 -->
  <view class="seekAdviceFrom">
    <view class="seekAdviceFrom-title flexjcsb" v-if="isHader">
      <view class="seekAdviceFrom-title-left">
        <text></text>
        <text>今日资讯</text>
      </view>
      <view class="seekAdviceFrom-title-right" @click="more">
        <text>更多</text><uni-icons type="right" color="#888888" size="28rpx"></uni-icons>
      </view>
    </view>
    <view class="" v-if="postList.length > 0">
      <view class="seekAdviceFrom-item" v-for="(item, index) in postList" :key="item.id" @click="looKInfo(item)">
        <view class="seekAdviceFrom-item-title">
          {{ item.title }}
        </view>
        <view class="seekAdviceFrom-item-image">
          <image :src="item.image" mode="aspectFit"></image>
        </view>
        <view class="seekAdviceFrom-item-notes">
          <view class="seekAdviceFrom-item-notes-left">
            <text>{{ item.create_time }}</text>
          </view>
          <view class="seekAdviceFrom-item-notes-right">
            <!-- 点赞 -->
            <view class="" @click.stop="eventLike(item, index)">
              <image v-if="item.is_like" src="@/static/xiaoyutong/likeSelected.png"></image>
              <image v-else src="@/static/xiaoyutong/like.png"></image>
              <text>{{ item.like_num }}</text>
            </view>
            <!-- 评论数 -->
            <view class="">
              <image src="@/static/xiaoyutong/comment.png" mode=""></image>
              <text>{{ item.comment_count }}</text>
            </view>
          </view>
        </view>
      </view>
    </view>

  </view>
</template>

<script>
const $api = require('@/utils/request.js').API
export default {
  props: ['isHader'],
  data() {
    return {
      // 列表
      postList: [],
      page: 1,
      page_count: 1,
    }
  },

  methods: {
    // 获取今日资讯列表
    getPostList() {
      $api.informationList({ page: this.page }).then(res => {
        this.page_count = res.data.data.page_count
        let list = res.data.data.list
        list.forEach(item => {
          item.image = this.$image + item.image
        })
        if (this.page == 1) {
          this.postList = list

        } else {
          this.postList = [...this.postList, ...list]
        }
      })
    },
    // 触底
    reachBottom() {
      if (this.page == this.page_count) {
        uni.showToast({
          title: '没有更多了',
          icon: 'none'
        })
      } else {
        this.page = this.page + 1
        this.getPostList()
      }
    },
    // 查看详情
    looKInfo(item) {
      uni.navigateTo({
        url: '/pages_xiaoyutong/DynamicDetails?id=' + item.id
      })
    },
    // 点赞
    eventLike(item, index) {
      if (item.is_like) {
        item.is_like = false
        item.like_num = item.like_num - 1
      } else {
        item.is_like = true
        item.like_num = item.like_num + 1
      }
      $api.informationLike({ id: item.id }).then(res => {

      })
    },
    // 更多
    more() {
      uni.navigateTo({
        url: '/pages_xiaoyutong/TodaysInformation'
      })
    },
  },
}
</script>

<style scoped lang='scss'>
.seekAdviceFrom {
  // margin-top: 20rpx;
  background: #ffffff;

  .seekAdviceFrom-title {
    // height: 100rpx;
    padding: 30rpx 27rpx 0 30rpx;

    .seekAdviceFrom-title-left {
      display: flex;
      align-items: center;
      font-size: 32rpx;
      font-family: Source Han Sans CN;
      font-weight: 400;
      color: #333333;

      text:first-child {
        display: inline-block;
        width: 6rpx;
        height: 30rpx;
        background: #F14500;
        margin-right: 14rpx;
      }
    }

    .seekAdviceFrom-title-right {
      font-size: 28rpx;
      font-family: PingFang SC;
      font-weight: 400;
      color: #888888;
    }
  }

  .seekAdviceFrom-item {
    width: 690rpx;
    margin: auto;
    border-bottom: 1px solid #F3F3F3;

    .seekAdviceFrom-item-title {
      font-size: 28rpx;
      font-family: PingFang SC;
      font-weight: 400;
      color: #666666;
      padding: 44rpx 0 20rpx 0;
    }

    .seekAdviceFrom-item-image {
      image {
        width: 690rpx;
        height: 260rpx;
        border-radius: 20rpx;
      }
    }

    .seekAdviceFrom-item-notes {
      display: flex;
      justify-content: space-between;
      align-items: center;
      height: 70rpx;

      // padding: 30rpx 0 34rpx 0;
      .seekAdviceFrom-item-notes-left {
        font-size: 22rpx;
        font-family: PingFang SC;
        font-weight: 400;
        color: #666666;

        text:last-child {
          padding-left: 10rpx;
        }
      }

      .seekAdviceFrom-item-notes-right {
        display: flex;
        align-items: center;
        font-size: 22rpx;
        font-family: PingFang SC;
        font-weight: 400;
        color: #999999;

        image {
          width: 29rpx;
          height: 26rpx;
          margin-right: 10rpx;
        }

        view:last-child {
          padding-left: 42rpx;
        }
      }
    }
  }
}
</style>
